﻿using Confluent.Kafka;
using KafkaService;
using System;
using System.Threading.Tasks;

namespace DotNetCoreKafkaTest
{
    class Program
    {
        async static Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            //await Producer();
            IKafkaService kafkaService = new KafkaService.Implements.KafkaService();
            var user = new
            {

                name = "1",
                sex = "2"
            };
            for (int i = 0; i < 10000; i++)
            {
                await kafkaService.PublishAsync<dynamic>("test-topic", user);
            }
         
            Console.ReadLine();
        }

        public static async Task Producer()
        {

            var config = new ProducerConfig { BootstrapServers = "192.168.8.110:9092" };

            using (var p = new ProducerBuilder<Null, string>(config).Build())
            {
                try
                {
                    var dr = await p.ProduceAsync("test-topic", new Message<Null, string> { Value = "test" });
                    Console.WriteLine($"Delivered '{dr.Value}' to '{dr.TopicPartitionOffset}'");
                }
                catch (ProduceException<Null, string> e)
                {
                    Console.WriteLine($"Delivery failed: {e.Error.Reason}");
                }
            }
        }

     
    }
}
